<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use \Cache;
use DB;
class Tbgprs2Controller extends Controller
{	public $token=null;
    public function __construct(){
           if (!Cache::has('tbgprs2_id'))
            {
                //获取ind
                //$access_token = 2944168;
		$t = date("Y-m-d",strtotime("-1 day"));
                $openId = 'o3eaus8lUvK0eiWB2n4iU1TAdeDs';
                $user = DB::table('tbgprs2')->where('RXD_time','>',$t)->select('ind')->first();  //ind
                //$user = DB::table('tbmember')->where('openID',$openId)->first();  //名字
                if( !$user )
		{
                    $access_token =2963520;
		} 
                else{
                    $access_token = $user->ind;
                    Cache::put('tbgprs2_id',$access_token, 1460);
                    $this->token = Cache::get('tbgprs2_id');
		}
            }
			$this->token = Cache::get('tbgprs2_id');

    }
	public function get_tbgprs2_ind(){
		return $this->token;
	}
	public function https2_request($url,$data = null){
                 $curl = curl_init();
                 curl_setopt($curl, CURLOPT_URL, $url);
                 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
                 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
                 if (!empty($data)){
                  curl_setopt($curl, CURLOPT_POST, 1);
                 curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
                 }
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
                 $output = curl_exec($curl);
                 curl_close($curl);
                 return $output;

        }
	public function add_time()
	{	
		//$indm = Cache::get('tbgprs2_id');
		//DB::table('tb_ind')->update(['indm'=>$indm]);		
  		$value = Cache::pull('tbgprs2_id');
               	if ( $value )
		{
			return redirect()->action('Tbgprs2Controller@get_tbgprs2_ind');
			
		}
  
	}


}
